package sismed.gui.comando;

import sismed.negocio.modelo.*;
import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sismed.negocio.fachada.Fachada;

public class ComandoListarCadastros extends ComandoGenerico{
	
	@Override
	public void executar(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException 
	{
		if(request.getSession().getAttribute("tipoUsuario").equals(null))				
			response.sendRedirect("login.jsp");
		else{
			Fachada fachada = Fachada.getInstance();			
			
			List<Pessoa> lista = fachada.recuperarListaPessoas();			
			request.setAttribute("ListaCadastros", lista);
			request.setAttribute("teste", "ok");
			System.out.print("tamanho da lista " + lista.size());
			try
			{
				request.getRequestDispatcher("verPessoas.jsp").forward(request, response);
			} 
			catch (Exception e)
			{	
				request.setAttribute("msgerro", e.getMessage());		
					
				request.getRequestDispatcher("erro.jsp").forward(request, response);
			}
		}
	}
}
